# list1 = [1, 2, 3, 4, 5]
# list1.append(6)
# print(list1)
#
# list1.remove(3)
# print(list1)
#
# list1[1] = 8
# print(list1)
#
# print(list1.index(8))
#
# for i in list1:
#     print(i)
#
# list2 = [7, 8, 9]
# for i in list2:
#     list1.append(i)
# print(list1)
#
# list1.extend([10, 11, 12])
# print(list1)
#
# print(list1[2:5])
#
# list1.insert(2, 14)
# list1.insert(2, 13)
# print(list1)
#

# my_list = [3, "apple", 9, "banana", 7, "cherry", 2, "date", 5, "elderberry"]
# my_list.append("fig")
# print(my_list)
#
# my_list.remove("banana")
# print(my_list)
#
# my_list[my_list.index(7)] = "grape"
# print(my_list)
#
# print(my_list.index("cherry"))
#
# for i in my_list:
#     print(i)
#
# my_list.insert(my_list.index("cherry")+1, "kiwi")
# print(my_list)
#
# print(my_list[2])
#
# print(my_list[-2])
#
# print(my_list[2:7])
#
# print(my_list[::-1])
#
# # 对列表中的字符串进行排序，并保留数字在原位。
# # 提取所有字符串并排序 sorted() 字符串排序
# strings = sorted([item for item in my_list if isinstance(item, str)])
# str_index = 0  # 字符串指针
#
# # 遍历原始列表，替换字符串为排序后的字符串
# result = []
# for item in my_list:
#     if isinstance(item, str):
#         result.append(strings[str_index])
#         str_index += 1
#     else:
#         result.append(item)
#
# print(result)
# # n = 0
# # for i in my_list:
# #     if isinstance(i, int):
#
#
# # 将my_list中的数字替换为它们对应的字符串形式（如1->'one'），不改变列表中原有的字符串。
# # 定义数字到字符串的映射字典
# num_to_str = {
#     0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four',
#     5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine',
#     10: 'ten'
# }
#
# # 遍历并替换整数为对应字符串，保留原字符串不变
# converted_list = [
#     num_to_str[item] if isinstance(item, int) else item for item in my_list
# ]
#
# print(converted_list)

# ls1 = []
# for i in range(1,101):
#     if i % 2 == 0 :
#         ls1.append(i)
#
# print(ls1)
#
# ls1 = [num**2 for num in ls1]
# print(ls1)
#
# ls1 = [i for i in ls1 if i <= 1000] #列表推导式
# print(ls1)
#
# ls1 = ls1[::-1]
# print(ls1)
#
# print(ls1[:10])
#
# ls1.append([101,102,103])
# print(ls1)

ls2 = [11, 22, 33, 44, 55, 66, 77, 88, 99, 11, 99]
total = 0
for i in ls2:
    total += i
avg = total / len(ls2)
print(avg)

print(max(ls2))
print(min(ls2))

print(ls2.index(11))

result = []
for i in ls2:
    result.append(str(i))
print(result)

result2 = []
i = 0
while i < len(ls2):
    result2.append(str(ls2[i]))
    i += 1
print(result2)

ls3 = [float(i) for i in ls2]
print(ls3)

n = 0
for i in ls2:
    if i > 50:
        n += 1
print(n)

ls2.insert(2, 99)
print(ls2)

ls2.pop(-1)
print(ls2)

ls4 = [i*2 for i in ls2]
print(ls4)

less = [i for i in ls2 if i <= 50]
greater = [i for i in ls2 if i > 50]
print(less, greater)

dict1 = {ls2.index(i):i for i in ls2}
print(dict1)

for idx, i in enumerate(ls2):
    print(i, idx)

import random
print(random.choice(ls2))

with open('列表.txt', 'w', encoding='utf-8') as f:
    for item in ls2:
        f.write(str(item) + '\n')